<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>classwork2</title>
    <!-- <link rel="stylesheet" href="./css/animate.css"> -->
    <!-- <script src="./jquery/jquery-3.6.4.min.js"></script> -->
    <script src="./gsap/gsap.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        #main {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 400px;
            height: 400px;
            background-color: bisque;
            margin: 0 auto;
            text-align: center
            
        }

        .btn {
            margin: 30px;
            text-align: center;
            border-radius: 8px;
            width: 200px;
            border: 1px solid green;
        }
        .btn:hover {
            background-color: green;
            color: white;
        }
        .box {
            /* display: none; */
            position: fixed;
            display: flex;
            align-items: center;
            justify-content: center;
            /* text-align: center; */
            /* line-height: 40px; */
            top:-100px;
            border-radius: 6px;
            border: 1px solid #F56C6C;
            background-color: #FEF0F0;
            color: #F8A0A0;
            width: 300px;
            height: 40px;
            margin:0 auto;
            --animate-duration: 1s;
        }
        .box-icon {
            width: 20px;
            height: 20px;
            line-height: 20px !important;
            display: inline-block;
            border-radius: 50%;
            background-color: #F56C6C;
            color: white;
            margin-right: 10px;
        }
        .box-btn {
            font-size: 18px;
            border: none;
            color: #B6B5BB;
            /* margin-top: 60px; */
        }
    </style>
</head>

<body>

    <div id="main">
        <div class="box">
            <div class="box-icon">x</div>
            <span>Oops,This is a error message.</span>
            <button class="box-btn" onclick="del(event)">x</button>
        </div>
        <button class="btn" onclick="handler(event)">确定</button>
    </div>

    <script>
        const box = document.querySelector('.box')

        // 点击弹出消息
        function handler(e) {
            gsap.to(box,{
                duration:0.5,
                top:'40px',
                ease:'power2.out'
            })
        }
        // 点击关闭消息                                                         
        function del(e) {
            gsap.to(box,{
                duration:0.5,
                top:'-100px',
                ease:'power2.in',
                onComplete:()=>{
                    box.style.display = 'none'
                }
            })
        }
    </script>
</body>

</html>